<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.com">
<head>
    <meta charset="UTF-8">
    <title>商品信息修改</title>

    <script type="text/javascript">
        function showImg() {
            var f = new FileReader();
            f.onload = function (ev) {
                img.src = ev.target.result;
            }
            f.readAsDataURL(file.files[0]);
        }
    </script>

    <link rel="stylesheet" type="text/css" th:href="@{/css/admin.css}"/>
</head>
<body>
<div class="frm" style="width:600px;margin-top: 30px;">
    <div class="title">
        商品信息修改
    </div>
    <form action="/admin/goods/update_submit" method="post" enctype="multipart/form-data">
        <input type="hidden" name="goodsId" th:value="${goods.goodsId}"/>
        <table>
            <tr>
                <td>商品名称</td>
                <td>
                    <input type="text" name="goodsName" th:value="${goods.goodsName}" required/>
                </td>
            </tr>

            <tr>
                <td>商品价格</td>
                <td>
                    <input type="text" name="price" th:value="${goods.price}" required/>
                </td>
            </tr>

            <tr>
                <td>产地</td>
                <td>
                    <input type="text" name="address" th:value="${goods.address}" required/>
                </td>
            </tr>

            <tr>
                <td>生产日期</td>
                <td>
                    <input type="date" name="produceDate" required
                           th:value="${#dates.format(goods.produceDate,'yyyy-MM-dd')}"/>
                </td>
            </tr>

            <tr>
                <td>产品图片</td>
                <td>
                    <img th:src="${goods.picture}" width="80" height="100" id="img"/>
                    <br/>
                    <div></div>
                    <input type="file" name="file" id="file" onchange="showImg()"/>
                    <input type="hidden" name="picture" th:value="${goods.picture}"/>
                </td>
            </tr>

            <tr>
                <td>商品分类</td>
                <td>
                    <select name="category.categoryId">
                        <option value="">请选择</option>
                        <option th:each="c:${categoryList}"
                                th:value="${c.categoryId}"
                                th:text="${c.categoryName}"
                                th:selected="${c.categoryId==goods.category.categoryId}">
                        </option>
                    </select>
                </td>
            </tr>

            <tr>
                <td></td>
                <td>
                    <input type="submit" value="修改"/>
                </td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>